function y = vm_irf(F,J,Omega,H,nv,Omega1)
% function y = vm_irf(F,J,Omega,H,nv,Omega1)
%
% Inputs:
%  - F: companion form
%  - J: shock linear combination selector matrix
%  - Omega: shock vector matrix 
%  - H: impulse response horizon
%  - nv: number of variables
%  - Omega1: shock vector matrix
%
% Outputs:
%  - y: IRF matrix

% Based on replication codes for Dario Caldara and Christophe Kamps (2017), The Analytics of SVARs: A
% Unified Framework to Measure Fiscal Multipliers, Review of Economic Studies (2017) 84, 1015–1040
%
% Copyright: 2017 Dario Caldara and Christophe Kamps
% Copyright: 2020-2023 Benjamin Born, Francesco D'Ascanio, Gernot J. Mueller, Johannes Pfeifer

nshock = size(Omega,2);
y = zeros(H,nv,nshock);

Omega1(1:nv,1:size(Omega1,2)) = Omega;
% COMPUTE IRFs
Ftemp = F^0;

for ii=1:H
    ytemp = J'*(Ftemp)*Omega1;
    y(ii,:,:) = ytemp;

    Ftemp = Ftemp*F;
end